package com.csnf.dto;

import lombok.Data;

@Data
public class ResponseObject {
    //响应码
    private int code;
    //信息
    private String msg;
    //数据
    private Object data;
    //直接返回
    public static ResponseObject success(){
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(true);
        responseObject.setCode(200);
        responseObject.setMsg("success");
        return responseObject;
    }
    //返回信息
    public static ResponseObject success(String msg){
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(true);
        responseObject.setCode(200);
        responseObject.setMsg(msg);
        return responseObject;
    }
    //返回数据
    public static ResponseObject success(Object data){
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(data);
        responseObject.setCode(200);
        responseObject.setMsg("success");
        return responseObject;
    }
    //自定义返回信息和数据
    public static ResponseObject success(String msg,Object data){
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(data);
        responseObject.setCode(200);
        responseObject.setMsg(msg);
        return responseObject;
    }
    //自定义返回信息
    public static ResponseObject error(String msg){
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(false);
        responseObject.setCode(400);
        responseObject.setMsg(msg);
        return responseObject;
    }
    //自定义返回数据和内容
    public static ResponseObject error(String msg,Object data){
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(data);
        responseObject.setCode(400);
        responseObject.setMsg(msg);
        return responseObject;
    }
    //直接返回
    public static ResponseObject error(){
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(false);
        responseObject.setCode(400);
        responseObject.setMsg("Fail");
        return responseObject;
    }
    //自定义返回信息和编码
    public static ResponseObject error(String msg,int code){
        ResponseObject responseObject = new ResponseObject();
        responseObject.setData(false);
        responseObject.setCode(code);
        responseObject.setMsg(msg);
        return responseObject;
    }

}
